file(GLOB MODULE_HEADERS CONFIGURE_DEPENDS "*.h")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

set(module_file_names "")
foreach(name ${MODULE_HEADERS})
    get_filename_component(filename ${name} NAME)
    set(module_file_names ${module_file_names} ${filename})
endforeach(name ${MODULE_HEADERS})

add_custom_command(
    OUTPUT ${CMAKE_BINARY_DIR}/module_glue.cpp
    DEPENDS ${MODULE_HEADERS}
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/jse/modules
    COMMAND ${CMAKE_COMMAND} -E echo "generate file: ${CMAKE_BINARY_DIR}/module_glue.cpp"
    COMMAND python3 "${CMAKE_SOURCE_DIR}/third_party/quickjspp/binding-generator/generator.py" -std=c++1z ${module_file_names} > ${CMAKE_BINARY_DIR}/module_glue.cpp
)

add_library(jse_module_glue
    ${CMAKE_BINARY_DIR}/module_glue.cpp
)

target_include_directories(jse_module_glue PRIVATE
    ${CMAKE_SOURCE_DIR}/src/jse/modules
    ${CMAKE_SOURCE_DIR}/third_party/quickjspp
)
